﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using erpIngesup.Models;
using erpIngesup.Functions;

namespace erpIngesup.Areas.Eleve.Controllers
{
    public class ResultController : Controller
    {
        private erpInsiaEntities db = new erpInsiaEntities();
        //
        // GET: /Eleve/Result/

        public ActionResult Index(string langue)
        {
            try
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Field.getLanguage(langue));
                string login = Session["login"] != null ? Session["login"].ToString() : "";
                string year = DateTime.Now.Year.ToString();
                var classe = db.ELEVECLASSE.SingleOrDefault(x => x.LOGINPERS == login && x.ANNEECLASSE == year);
                var module = db.MODULE.Where(x => x.CLASSE.LIBCLASSE == classe.CLASSE.LIBCLASSE).ToList();
                return View(module);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return View("error");
            }
        }

        public ActionResult Notes(string module, string langue)
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Field.getLanguage(langue));
            string login = Session["login"] != null ? Session["login"].ToString() : "";
            var notes = db.ELEVEEVAL.Where(x => x.LOGINPERS == login && x.EVALUATION.ID_MOD == module).ToList();
            return View(notes);
        }

        public ActionResult Details(string langue, int idEval)
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Field.getLanguage(langue));
            string login = Session["login"] != null ? Session["login"].ToString() : "";
            EVALUATION eval = db.EVALUATION.SingleOrDefault(x => x.IDEVAL == idEval);
            return View(eval);
        }

    }
}
